import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreWechatTemplateService extends BaseService<any> {
  private readonly logger = new Logger(CoreWechatTemplateService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * send
   * 对应 PHP: CoreWechatTemplateService_core::send()
   * 逻辑类型: undefined - undefined
   */
  async send(site_id: any[], open_id: any[], wechat_template_id: any[], data: any[], first: any[], remark: any[], url: any[], miniprogram: any[]) {
    // 基于PHP真实逻辑: send
    // PHP原文: if (!empty($first)) $data[ 'first' ] = $first;         if (!empty($remark)) $data[ 'remark' ] = $remark;         $api = CoreWechatService::appApiClien...
if (!!first)) data[ 'first' ] = first;
        if (!!remark)) data[ 'remark' ] = remark;
        const api = CoreWechatService.appApiClient(site_id];
        const param = [
            touser: open_id,
            template_id: wechat_template_id,
            url: url,
            miniprogram: miniprogram,
            data: data,
        );
        if(!!client_msg_id)){
            param.client_msg_id = client_msg_id;
  }

  /**
   * deletePrivateTemplate
   * 对应 PHP: CoreWechatTemplateService_core::deletePrivateTemplate()
   * 逻辑类型: undefined - undefined
   */
  async deletePrivateTemplate(site_id: number, templateId: number) {
    // 基于PHP真实逻辑: deletePrivateTemplate
    // PHP原文: $api = CoreWechatService::appApiClient($site_id);          return $api->postJson('cgi-bin/template/del_private_template', [             'template_id' ...
const api = CoreWechatService.appApiClient(site_id);

        return api.postJson('cgi-bin/template/del_private_template', [
            template_id: templateId,
        )];
    }

    /**
     * 添加
     * @param int site_id
     * @param string shortId
     * @param string keyword_name_list
     * @return array|Collection|object|ResponseInterface|string
     * @throws GuzzleBusinessException
     * @throws InvalidConfigBusinessException
     */
    async addTemplate(int site_id, string shortId, string keyword_name_list)
    {
        const api = CoreWechatService.appApiClient(site_id);

        return api.postJson('cgi-bin/template/api_add_template', [
            template_id_short: shortId,
            keyword_name_list: keyword_name_list
        );
  }
  }

  /**
   * addTemplate
   * 对应 PHP: CoreWechatTemplateService_core::addTemplate()
   * 逻辑类型: undefined - undefined
   */
  async addTemplate(site_id: number, shortId: number, keyword_name_list: number) {
    // 基于PHP真实逻辑: addTemplate
    // PHP原文: $api = CoreWechatService::appApiClient($site_id);          return $api->postJson('cgi-bin/template/api_add_template', [             'template_id_short...
const api = CoreWechatService.appApiClient(site_id);

        return api.postJson('cgi-bin/template/api_add_template', [
            template_id_short: shortId,
            keyword_name_list: keyword_name_list
        );
  }
  }
}
